package com.swu.education.service;

import com.swu.education.entity.Activity;
import com.swu.education.entity.Assignment;
import com.swu.education.repository.ActivityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by nana on 2018/3/18.
 */
@Service
public class ActivityService {

  @Autowired
  ActivityRepository activityRepository;

  public Activity getSingleActivityById(int assignmrntId){
    return activityRepository.findOne(assignmrntId);
  }

  public List<Activity> getActivityListByAssignmentId(int assignmentId){
    List<Activity> allActivityListByAssignmentId =  activityRepository.findAllByAssignmentId(assignmentId);
    return allActivityListByAssignmentId;
  }
  public Activity createActivityByAssignmentId(int assignmentId,String activityName,String type,
                                               String description,String startTime,String endTime){
    //创建activity类并赋值
    Activity activity = new Activity();
    activity.setAssignmentId(assignmentId);
    activity.setActivityName(activityName);
    activity.setType(type);
    activity.setDescription(description);
    activity.setStartTime(startTime);
    activity.setEndTime(endTime);
    //存储activity
    activityRepository.save(activity);
    return activity;
  }

  //删除activity
  public void deleteActivityIdById(int activityId){
    activityRepository.delete(activityId);
  }
  // 修改activity信息
  public void modifyActivityInfoById(int activityId,String activityName,String type,
                                     String description,String startTime,String endTime){
    Activity activity = activityRepository.findOne(activityId);

    activity.setActivityName(activityName);
    activity.setType(type);
    activity.setDescription(description);
    activity.setStartTime(startTime);
    activity.setEndTime(endTime);
    activityRepository.save(activity);
  }
}
